iT邦幫忙

2023 iThome 鐵人賽

DAY 16
0
Mobile Development

App從開發到上架系列 第 16

Day18: iOS 開發:畫面功能(電子錢包) - 金流的SandBox

  • 分享至 

  • xImage
  •  
import UIKit
import PassKit

class WalletViewController: BaseViewController {
    
    
    
    private var paymentRequset: PKPaymentRequest = {
        let request = PKPaymentRequest()
        request.merchantIdentifier = "merchant.你的appBundleID"
        request.supportedNetworks = [.visa]
        request.supportedCountries = ["TW"]
        request.merchantCapabilities = .capability3DS
        request.currencyCode = "TWD"
        request.countryCode = "TW"
        request.paymentSummaryItems = [PKPaymentSummaryItem(label: "iphone", amount: 31500)]
        return request
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = .black
        print("you enter WalletViewController!")
    }
    
    @IBAction func pat(_ sender: Any) {
        applePay()
    }
    
    
    func applePay() {
        let controller = PKPaymentAuthorizationViewController(paymentRequest: paymentRequset)
        if controller != nil {
            controller!.delegate = self
            present(controller!, animated: true) {
                print("success")
            }
            
        }
    }
}

extension WalletViewController: PKPaymentAuthorizationViewControllerDelegate {
    func paymentAuthorizationViewControllerDidFinish(_ controller: PKPaymentAuthorizationViewController) {
        controller.dismiss(animated: true)
    }
    
    func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController, didAuthorizePayment payment: PKPayment, handler completion: @escaping (PKPaymentAuthorizationResult) -> Void) {
        completion(PKPaymentAuthorizationResult(status: .success, errors: nil))
    }
}

上一篇
Day16: iOS 開發:畫面功能(最新消息) - Notification
下一篇
Day19: iOS 開發:畫面建構(查找附近餐廳) - FindRestaurantViewController
系列文
App從開發到上架30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言